# 元组(Tuple)
tuple1 = (1, 2, 3, True, "Hello", 3.14)
print(tuple1)
print(type(tuple1))

tuple2 = (1,)  # 只有一个元素的元组要加逗号
print(tuple2)
print(type(tuple2))

tuple3 = ()  # 空元组
print(tuple3)
print(type(tuple3))

# 元组的类型转换
tuple4 = tuple('hello')  # str -> tuple
print(tuple4)
print(type(tuple4))

tuple5 = tuple([1, 2, 3, 4, 5])  # list -> tuple
print(tuple5)

list1 = list(tuple5)  # tuple -> list
print(list1)

str1 = str(tuple5)  # tuple -> str 原封不动的输出
print(str1)

# 元组和序列的通用方法：len()、min()、max()、sum()、sorted()

# 元组的操作：
tuple6 = (1, 2, 3, 4, 5, 5)
print(tuple6.count(5))  # 统计元组中某个元素出现的次数

print(tuple6.index(5))  # 找出元组中某个元素的索引

# 元组的遍历：
print('-' * 20)
for i in tuple6:
    print(i)

for i,j in enumerate(tuple6):
    print(i,j)

for i in range(len(tuple6)):
    print(i, tuple6[i])